package com.diqizu.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import com.diqizu.entity.IntroDuctionEntity;
import com.diqizu.entity.Users;
import com.diqizu.entity.MessaGeEntity;
import com.diqizu.entity.DesignerEntity;
import com.diqizu.utli.DBManager;
import com.diqizu.utli.QueryDataResult;
/*
private String Name;
private int Telephone;
private String Email;
private String Contentt;*/

public class SheJiDao {
  // 留言版添加方法
  public boolean addmessage(MessaGeEntity e) {
    String sql = "insert message (name,telephone,email,contentt) values ('" + e.getName() + "','" + e.getTelephone()
        + "','" + e.getEmail() + "','" + e.getContentt() + "')";
    boolean num = DBManager.execUpdate(sql);
    System.out.println(sql);
    System.out.println(num);
    if (num == true) {
      return true;
    }
    return false;
  }

  public ArrayList<MessaGeEntity> adminmessage() {
    System.out.println("全查Introduction");
    ArrayList<MessaGeEntity> list = new ArrayList<>();
    QueryDataResult executeQuery = DBManager.execQuery("select * from message");
    if (executeQuery != null) {
      ResultSet rs = executeQuery.rs;
      try {
        while (rs.next()) {
          MessaGeEntity e = new MessaGeEntity(rs.getInt(1), rs.getString(2), rs.getString(3), rs.getString(4),
              rs.getString(5), rs.getString(6));
          list.add(e);
        }
      } catch (SQLException e) {
        e.printStackTrace();
      } finally {
        executeQuery.close();
      }
    }

    return list;
  }

  // 留言板修改admin
  public boolean addmessageadmin(MessaGeEntity e) {
    String sql = "insert message (text) values ('" + e.getText() + "') where id=" + e.getId();
    boolean num = DBManager.execUpdate(sql);
    System.out.println(sql);
    System.out.println(num);
    if (num == true) {
      return true;
    }
    return false;
  }

  // 公司介绍修改
  public boolean addIntroduction(IntroDuctionEntity e) {
    String sql = "update introduction set Content='" + e.getContent() + "',Content2='" + e.getContent2()
        + "',gourl='" + e.getGourl() + "',Content3='" + e.getContent3() + "',gourl2='" + e.getGourl2()
        + "' where id=1";
    boolean num = DBManager.execUpdate(sql);
    System.out.println(sql);
    System.out.println(num);
    if (num == true) {
      return true;
    }
    return false;
  }

//公司介绍全查
  public ArrayList<IntroDuctionEntity> Introduction() {
    System.out.println("全查Introduction");
    ArrayList<IntroDuctionEntity> list = new ArrayList<>();
    QueryDataResult executeQuery = DBManager.execQuery("select * from Introduction");
    if (executeQuery != null) {
      ResultSet rs = executeQuery.rs;
      try {
        while (rs.next()) {
          IntroDuctionEntity e = new IntroDuctionEntity(rs.getInt(1), rs.getString(2), rs.getString(3),
              rs.getString(4), rs.getString(5), rs.getString(6), rs.getString(7));
          list.add(e);
        }
      } catch (SQLException e) {
        e.printStackTrace();
      } finally {
        executeQuery.close();
      }
    }

    return list;
  }
  //全查密码
  public ArrayList<Users> chamima() {
	    System.out.println("管理员");
	    ArrayList<Users> list = new ArrayList<>();
	    QueryDataResult executeQuery = DBManager.execQuery("select * from users");
	    if (executeQuery != null) {
	      ResultSet rs = executeQuery.rs;
	      try {
	        while (rs.next()) {
	        	Users e = new Users(rs.getString(2), rs.getString(3),
	              rs.getString(4));
	          list.add(e);
	        }
	      } catch (SQLException e) {
	        e.printStackTrace();
	      } finally {
	        executeQuery.close();
	      }
	    }

	    return list;
	  } 
  //修改密码
  public boolean xiumima(Users e) {
		    String sql = "update users set userPwd='" + e.getUserPwd() + "',userName='" + e.getUserName() + "' where id=1";
	    boolean num = DBManager.execUpdate(sql);
	    System.out.println(sql);
	    System.out.println(num);
	    if (num == true) {
	      return true;
	    }
	    return false;
	  }

//设计师全查
  public ArrayList<DesignerEntity> designer() {
    System.out.println("全查designer");
    ArrayList<DesignerEntity> list = new ArrayList<>();
    QueryDataResult executeQuery = DBManager.execQuery("select * from designer");
    if (executeQuery != null) {
      ResultSet rs = executeQuery.rs;
      try {
        while (rs.next()) {
          DesignerEntity e = new DesignerEntity(rs.getInt(1), rs.getString(2), rs.getString(3),
              rs.getString(4), rs.getString(5), rs.getString(6));
          list.add(e);
        }
      } catch (SQLException e) {
        e.printStackTrace();
      } finally {
        executeQuery.close();
      }
    }

    return list;
  }

  // 添加设计师
  public boolean addsheji(DesignerEntity e) {
    boolean num = DBManager.execUpdate("insert designer(name,sex,Position,url,xiuTime) values ('" + e.getName()
        + "','" + e.getSex() + "','" + e.getPosition() + "','" + e.getUrl() + "','" + e.getXiuTime() + "')");
    if (num == true) {
      System.out.println("修改成功");
      return true;
    }
    System.out.println("修改失败");
    return false;
  }

  // 删除设计师
  public boolean delsheji(int id) {
    boolean num = DBManager.execUpdate("delete from designer where id=" + id);
    if (num == true) {
      System.out.println("修改成功");
      return true;
    }
    System.out.println("修改失败");
    return false;

  }

  // 修改设计师
  public boolean updatesheji(DesignerEntity e) {
    String sql = "update designer set name = '" + e.getName() + "',sex ='" + e.getSex() + "',Position ='"
        + e.getPosition() + "',url ='" + e.getUrl() + "',xiuTime ='" + e.getXiuTime() + "'where id="
        + e.getId();
    boolean num = DBManager.execUpdate(sql);
    System.out.println(sql);
    if (num == true) {
      System.out.println("修改成功");
      return true;
    }
    System.out.println("修改失败");
    return false;

  }

  public boolean updateliuyan(MessaGeEntity e) {
    String sql = "update message set text = '" + e.getText() + "'where id=" + e.getId();
    boolean num = DBManager.execUpdate(sql);
    System.out.println(sql);
    if (num == true) {
      System.out.println("修改成功");
      return true;
    }
    System.out.println("修改失败");
    return false;

  }

}
